package Qieces;

import java.awt.*;

/**
 * 士类
 *
 */
public class Assistant extends Qiece{

    public Assistant(Qiece a,int index,int c){

        if (index == 0){
            this.kind = 2;
            this.x = a.x;
            this.y = a.y;
            this.controller = c;
            this.moveof = 0;
        }else if (index == 1){
            this.kind = a.kind;
            this.controller = a.controller;
        }
        this.scl = 0;
    }

    @Override
    public void paintSelf(Graphics g) {
        if(this.controller == 0 && this.kind !=0){           //为黑子时
            g.drawImage(assistants_b,x,y,null);
        } else if(this.controller == 1 && this.kind !=0){    //为红子时
            g.drawImage(assistants_r,x,y,null);
        }
        if(this.moveof == 1){
            g.drawImage(point,x+10,y+10,null);
        }
    }

    @Override
    public void movingRange(Qiece[] qieces, int row, int col) {
        int [] a=new int [2];
        int [] b=new int [2];
        a[0]=1;a[1]=-1;
        b[0]=-1;b[1]=1;
        if(row<5){
            for(int i=0;i<2;i++){
                for(int j=0;j<2;j++){
                    if(row+a[i]>=0 && row+a[i]<3 && col+b[j]>=3 && col+b[j]<6 ){
                        if(qieces[(row+a[i])*9+col+b[j]].controller!=this.controller||qieces[(row+a[i])*9+col+b[j]].kind==0) {
                            qieces[(row+a[i])*9+col+b[j]].moveof=1;
                        }
                    }
                }
            }
        }
        else{
            for(int i=0;i<2;i++){
                for(int j=0;j<2;j++){
                    if(row+a[i]>=7 && row+a[i]<10 && col+b[j]>=3 && col+b[j]<6 ){
                        if(qieces[(row+a[i])*9+col+b[j]].controller!=this.controller||qieces[(row+a[i])*9+col+b[j]].kind==0) {
                            qieces[(row+a[i])*9+col+b[j]].moveof=1;
                        }
                    }
                }
            }
        }
    }
}
